package com.l.web.master.index;

import com.l.web.master.system.config.Config;
import com.l.web.master.system.config.ConfigDAO;
import com.l.web.master.system.menu.MenuDAO;
import org.l.qiao.Cluster;
import org.l.qiao.search.Query;
import org.l.qiao.web.ServiceSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class IndexService extends ServiceSupport {
    @Autowired
    private MenuDAO menudao;
    @Autowired
    private ConfigDAO configdao;
    private Config system = new Config();

    public String index(Map modelMap) {
        List<Cluster> menu0 = menudao.findByParentid(null);
        List<Cluster> menu1;

        if (!menu0.isEmpty()) {
            Cluster mm = menu0.get(0);
            menu1 = menudao.findByParentid(mm.getId());
        } else {
            menu1 = new ArrayList();
        }

        Query query = new Query();
        query.eq(system.NAME, "system");
        system.putAll(configdao.findOne(query));

        modelMap.put("menu0", menu0);
        modelMap.put("menu1", menu1);
        modelMap.put("system", system);
        return "success";
    }

    public List<Cluster> getChildrenMenu(String parentId) {
        List<Cluster> menus = menudao.findByParentid(parentId);
        return menus;
    }
}
